package com20230213;

import java.util.Arrays;

public class Score {
    public static void main(String[] args) {

        String[] names = {"安琪拉","王昭君","蔡文姬","妲己","张良"};

        String[] courses = {"C++","Java","English"};

        int[][] scores = {
                { 90, 89, 75 },
                { 59, 40, 100 },
                { 100, 99, 80 },
                { 80, 61, 61 },
                { 60, 100, 99 },
        };

        //输出每个学生的姓名以及该学生各门课程的成绩
        for (int i = 0; i < scores.length; i++) {
            System.out.print( names[i] + " => ");
            for (int j = 0; j < scores[i].length ; j++) {
                System.out.print( courses[j] + " : ");
                System.out.print( scores[i][j] );
                if ( j < scores[i].length - 1) {
                    System.out.print( "," );
                }

            }
            System.out.println();

        }


        //按照各个学生的英语成绩进行排序（降序）
        for (int i = 0; i < scores.length - 1; i++) {
            for (int j = 0; j < scores.length - 1 - i; j++) {
                int f = scores[j][2];
                int s = scores[j+1][2];
                if (f < s){
                    int[] temp = scores[j];
                    scores[j] = scores[j+1];
                    scores[j+1] = temp;

                    String x = names[j];
                    names[j] = names[j+1];
                    names[j+1] = x;


                }
            }


        }
        for (int j = 0; j < 5; j++) {

                System.out.println("姓名：" + names[j] + "英语：" + scores[j][2]);



        }

        //总成绩
        int[] sums = new int[names.length];

        for (int i = 0; i < scores.length; i++) {
            for (int j = 0; j < scores[i].length; j++) {

                sums[i] += scores[i][j];

            }
        }
        System.out.println(Arrays.toString( sums ) );

        //冒泡排序
        for (int i = 0; i < sums.length; i++) {
            for (int j = 0; j < sums.length - 1 - i ; j++) {
                if(sums[j] < sums[j+1]){
                    int temp = sums[j];
                    sums[j] = sums[j+1];
                    sums[j+1] = temp;

                    String x = names[ j ];
                    names[ j ] = names[ j + 1 ];
                    names[ j + 1 ] = x ;

                    int[] score = scores[j] ;
                    scores[j] = scores[j+1];
                    scores[j+1] = score;

                }


            }

        }
        for (int i = 0; i < scores.length; i++) {
            System.out.print("姓名是" + names[i] + "的总分是：" + sums[i]  + "\t");
            for (int j = 0; j < scores[i].length; j++) {
                System.out.print(courses[j] + "成绩是：" + scores[i][j]);


            }
            System.out.println();
        }





    }
}
